home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MCASM.RAR / MC_ASM.EXE / WROX_ASM / CH12 / RASTFONT / PUTSTR.ASM < prev   
Assembly Source File  |  1994-11-16  |  7KB  |  429 lines

  1. ; This program defines procedure OverlapString, that displays
  2. ; a text string on EGA/VGA in 16 colors graphics mode using specified
  3. ; raster font.
  4.  
  5. .model large
  6.  
  7. .data
  8.  
  9. BytesPerLine dw 80
  10. _FontColor db 15
  11.  
  12. ; Output is clipped to the view port defined below
  13. ViewPortleft dw 0
  14. ViewPorttop dw 0
  15. ViewPortright dw 639
  16. ViewPortbottom dw 479
  17.  
  18. public _DispalyString
  19. public _FontColor
  20.  
  21. .code
  22.  
  23. ; Call: DispalyString( int X, int Y, void* StrVar,
  24. ;                      void* CurrentFontPtr, int CharHeight, int CharWidth);
  25.  
  26. X               EQU word ptr [bp+6]
  27. Y               EQU word ptr [bp+8]
  28. StrVar          EQU dword ptr [bp+10]
  29. StrVarAOffs     EQU word ptr [bp+10]
  30. CurrentFontPtr  EQU dword ptr [bp+14]
  31. CharHeight    EQU byte ptr [bp+18]
  32. CharWidth    EQU byte ptr [bp+20]
  33.  
  34. ; Local variables:
  35.  
  36. OurCharHeight   EQU byte ptr [bp-1]
  37. OurCharWidth    EQU byte ptr [bp-2]
  38. VBOffs          EQU word ptr [bp-4]
  39. BChar           EQU byte ptr [bp-5]
  40. OurStrLength    EQU byte ptr [bp-6]
  41. BCMask          EQU byte ptr [bp-7]
  42. ECMask          EQU byte ptr [bp-8]
  43. DecBytesPerLine EQU word ptr [bp-10]
  44. SolidFColor    EQU byte ptr [bp-11]
  45. AbsCharHeight   EQU byte ptr [bp-12]
  46. VideoSelector    EQU word ptr [bp-14]
  47.  
  48. _DispalyString    proc far
  49.         push bp
  50.         mov bp,sp
  51.         sub sp,14
  52.         push ds
  53.         push di
  54.         push si
  55.  
  56.         ; Initialize locals
  57.         mov ax,0a000h
  58.         mov VideoSelector,ax
  59.         mov ax,@data
  60.         mov es,ax
  61.         mov ax,BytesPerLine
  62.         dec ax
  63.         mov DecBytesPerLine,ax
  64.         mov al,_FontColor
  65.         mov SolidFColor,al
  66.         mov VBOffs,0
  67.  
  68.         ; Check vertical coordinates for clipping
  69.         xor bx,bx
  70.         mov si,ViewPortbottom
  71.         mov di,ViewPorttop
  72.         mov ax,Y
  73.         add ax,di
  74.         mov Y,ax
  75.         cmp ax,si
  76.         jle VCE1     ; check string top & ViewPort bottom
  77.         jmp EC10    ; string invisible
  78. VCE1:
  79.         mov bl,CharHeight
  80.         mov dl,bl
  81.         cmp ax,di
  82.         jge VCE2     ; check string top & ViewPort top
  83.         mov dx,di
  84.         sub dx,ax
  85.         mov VBOffs,dx
  86.         neg dl
  87.         add dl,bl
  88.         mov Y,di
  89. VCE2:
  90.         add ax,bx
  91.         dec ax
  92.         cmp ax,di
  93.         jge VCE3        ; check string bottom  & ViewPort top
  94.         jmp EC10    ; string invisible
  95. VCE3:
  96.         sub ax,si
  97.         jl VCE4        ; check string bottom  & ViewPort bottom
  98.         sub dl,al
  99. VCE4:
  100.         mov OurCharHeight,dl
  101.  
  102.         ; Check horisontal coordinates
  103.         mov BCMask,0
  104.         mov si,ViewPortRight
  105.         mov cx,ViewPortleft
  106.         mov ax,X
  107.         add ax,cx
  108.         mov X,ax
  109.         cmp ax,si
  110.         jle HCE1    ; check string left & ViewPort right
  111.         jmp EC10    ; string invisible
  112. HCE1:
  113.         mov BChar,bl    ; store AbsCharHeight
  114.         les bx,StrVar   ; ES:BX -> String
  115.         push bx
  116.         mov dl,0
  117.  
  118.         ; Find terminating zero and initialize char counter
  119. find_0:
  120.         mov dh,es:[bx]
  121.         or dh,dh
  122.         jz end_line
  123.         inc dl
  124.         inc bx
  125.         jmp short find_0
  126. end_line:
  127.         pop bx
  128.         mov dh,dl
  129.         mov OurStrLength,dh    ; char counter
  130.         mov dl,CharWidth
  131.         mov OurCharWidth,dl
  132.         mov ECMask,dl
  133.         mov di,ax
  134.         cmp ax,cx
  135.         jge HCE2    ; check string left & ViewPort left
  136.         neg ax
  137.         add ax,cx
  138.         div dl
  139. WCut:
  140.         cmp al,dh
  141.         jl HCPE
  142.         jmp EC10    ; string invisible
  143. HCPE:
  144.         mov di,cx
  145.         and ah,ah
  146.         je BMzero
  147.         mov BCMask,ah
  148.         inc al
  149. BMzero:
  150.         xor ah,ah
  151.         mov cl,dh
  152.         sub cl,al
  153.         mov OurStrLength,cl
  154.         add bx,ax
  155. HCE2:
  156.         mov cl,OurStrLength
  157.         mov al,dh
  158.         mul dl
  159.         add ax,X
  160.         dec ax
  161.         sub ax,si
  162.         jle AllChEnd
  163.         div dl
  164.         cmp ah,0
  165.         je WCut2
  166.         inc al
  167.         sub ECMask,ah
  168. WCut2:
  169.         sub cl,al
  170.         mov OurStrLength,cl
  171. AllChEnd:
  172.         push ds
  173.         mov StrVarAOffs,bx
  174.         mov dx,3ceh
  175.         mov ax,0805h
  176.         out dx,ax     ; Set write mode 0 (normal)
  177.         mov ax,0ff01h
  178.         out dx,ax     ; Enable Set/Reset
  179.         mov al,0
  180.         mov ah,SolidFColor
  181.         out dx,ax     ; Set color
  182.         mov al,8
  183.         out dx,al    ; Set register index to Mask Register
  184.  
  185.         ; Calulate start offset in video buffer
  186.         mov bl,cl
  187.         mov ax,Y
  188.         mul BytesPerLine    ; YCoord * BytesPerLine
  189.         mov dx,di
  190.         mov di,ax
  191.         mov ax,dx
  192.         mov cl,3
  193.         shr ax,cl
  194.         mov cx,dx
  195.         and cx,7
  196.         add di,ax
  197.  
  198.         lds si,CurrentFontPtr
  199.         add si,VBOffs
  200.         mov al,BChar
  201.         mov AbsCharHeight,al
  202.  
  203.         mov al,ECMask
  204.         sub al,OurCharWidth
  205.         or al,BCMask
  206.         jnz CharCuting ; Clip to view port
  207. HSpeedDC:
  208.         mov dx,3cfh
  209.         mov ax,StrVarAOffs
  210.         xor bh,bh
  211.         add bx,ax
  212.         xchg bx,ax
  213.         mov VBOffs,ax
  214.  
  215.         ; Main loop (string output)
  216. PutEGALoop:
  217.         push si
  218.         push es
  219.         push di
  220.         call PutEGAChar ; char by char
  221.         pop di
  222.         pop es
  223.         pop si
  224.  
  225.         add cl,OurCharWidth
  226.         cmp cl,08
  227.         jl OldVByte
  228.         inc di
  229.         and cl,07
  230. OldVByte:
  231.         inc bx
  232.         cmp bx,VBOffs
  233.         jl PutEGALoop ; Next char
  234. By_By:
  235.         ; Restore default ports values
  236.         mov dx,3ceh
  237.         mov ax,0001H
  238.         out dx,ax
  239.         mov ax,0FF08H
  240.         out dx,ax
  241.         mov ax,0005
  242.         out dx,ax
  243.         pop ds
  244. EC10:
  245.         pop si
  246.         pop di
  247.         pop ds
  248.         mov sp,bp
  249.         pop bp
  250.         ret           ; Return from OverlapString
  251.  
  252.         ; Character fragment output (clipped)
  253. CharCuting:
  254.         or bl,bl
  255.         jl EandBcon
  256.  
  257.         mov BChar,cl
  258.         mov X,di
  259.  
  260.         mov dh,BCMask
  261.         or dh,dh
  262.         jz EMaskDrwng
  263.         mov dl,OurCharWidth
  264.         mov bx,StrVarAOffs
  265.         dec bx
  266.         push es
  267.         push si
  268.         call SpecPutEGAChar
  269.         pop si
  270.         pop es
  271.  
  272.         mov di,X
  273.         add cl,OurCharWidth
  274.         sub cl,BCMask
  275.         cmp cl,08
  276.         jl EMDg
  277.         inc di
  278.         and cl,07
  279.         mov X,di
  280. EMDg:
  281.         mov BChar,cl
  282. EMaskDrwng:
  283.         mov dl,ECMask
  284.         mov al,OurCharWidth
  285.         cmp dl,al
  286.         je RestorePars
  287.         mov dh,OurStrLength
  288.         mul dh
  289.         mov dh,al
  290.         mov ch,cl
  291.         mov cl,03
  292.         shr ax,cl
  293.         add di,ax
  294.         and dh,07
  295.         add dh,ch
  296.         mov al,dh
  297.         cbw
  298.         shr ax,cl
  299.         add di,ax
  300.         mov cl,dh
  301.         and cl,07
  302.         xor dh,dh
  303.         mov bx,StrVarAOffs
  304.         add bl,OurStrLength
  305.         adc bh,00
  306.         push es
  307.         push si
  308.         call SpecPutEGAChar
  309.         pop si
  310.         pop es
  311.         mov di,X
  312.         mov cl,BChar
  313. RestorePars:
  314.         mov bl,OurStrLength
  315.         or bl,bl
  316.         jz ABy_By
  317. NIncDI:
  318.         jmp HSpeedDC
  319. EandBcon:
  320.         mov dh,BCMask
  321.         mov dl,ECMask
  322.         mov bx,StrVarAOffs
  323.         dec bx
  324.         push es
  325.         call SpecPutEGAChar
  326.         pop es
  327. ABy_By:
  328.         jmp By_By
  329. _DispalyString    endp
  330.  
  331. ;---------     PutEGAChar
  332.  
  333. PutEGAChar    proc near
  334.         xor ax,ax
  335.         mov al,es:[bx]
  336.         mul AbsCharHeight
  337.         mov ch,OurCharHeight
  338.         add si,ax
  339.         mov es,VideoSelector
  340.  
  341.         or cl,cl
  342.         jnz NonByteAlign
  343. ByteAlignLoop:
  344.         mov al,[si]
  345.         out dx,al
  346.         xchg es:[di],al
  347.         inc si
  348.         add di,BytesPerLine
  349.         dec ch
  350.         JNZ ByteAlignLoop
  351.         jmp Happy
  352. NonByteAlign:
  353.         xor al,al
  354.         mov ah,[si]
  355.         shr ax,cl
  356.         xchg al,ah
  357.  
  358.         out dx,al
  359.         xchg es:[di],al
  360.         inc di
  361.         mov al,ah
  362.         out dx,al
  363.         xchg es:[di],al
  364.         inc si
  365.         add di,DecBytesPerLine
  366.         dec ch
  367.         jnz NonByteAlign
  368. Happy:
  369.         ret
  370. PutEGAChar    endp
  371.  
  372. ;---------------  SpecPutEGAChar
  373.  
  374. SpecPutEGAChar    proc near
  375.         xor ax,ax
  376.         mov al,es:[bx]
  377.         mul AbsCharHeight
  378.         mov ch,OurCharHeight
  379.         add si,ax
  380.         mov es,VideoSelector
  381.  
  382.         mov ax,0FF00H
  383.         xchg cl,dl
  384.         shr ah,cl
  385.         not ah
  386.         mov bl,ah         ;Zero-shr mask
  387.         mov bh,dh
  388.  
  389.         mov cl,dl
  390.         mov dx,3cfh
  391.         or cl,cl
  392.         jnz SNonByteAlign
  393. SByteAlignLoop:
  394.         mov al,[si]
  395.         and al,bl
  396.         xchg bh,cl
  397.         shl al,cl
  398.         xchg bh,cl
  399.         shr al,cl
  400.         out dx,al
  401.         xchg es:[di],al
  402.         inc si
  403.         add di,BytesPerLine
  404.         dec ch
  405.         jnz SByteAlignLoop
  406.         ret
  407. SNonByteAlign:
  408.         xor al,al
  409.         mov ah,[si]
  410.         and ah,bl
  411.         xchg bh,cl
  412.         shl ax,cl
  413.         xchg bh,cl
  414.         shr ax,cl
  415.         xchg al,ah
  416.         out dx,al
  417.         xchg es:[di],al        ; first half of char
  418.         inc di
  419.         mov al,ah
  420.         out dx,al
  421.         xchg es:[di],al        ; last half of char
  422.         inc si
  423.         add di,DecBytesPerLine
  424.         dec ch
  425.         jnz SNonByteAlign
  426.         ret
  427. SpecPutEGAChar    endp
  428. end
  429.